class DataCTI:
    
    def load(self,filename,NoP):
        """ Load CTI file
        """
        of = open(filename)
        lines = of.readlines()

        searchTermsVars = ['NAME ','VAR ','DATA ']
        searchTermsData = ['VAR_LIST_BEGIN','BEGIN']
        dataDict = {}
        l=0
        l2=0
        for i in range(1,len(lines)-1):
            line = lines[i]
                        
            for k,j in enumerate(searchTermsVars):
                
                index = str(line[0:len(j)]).find(j)

                if index != -1 and j!='DATA ':
                    dataDict[j[0:len(j)-1]] = line[len(j):-1]
                               
                if index != -1 and j=='DATA ':
                    dataDict[j[0:len(j)-1]+str(l)] = line[len(j):-1]
                    l += 1
            
            for k,j in enumerate(searchTermsData):
                index  = str(line[0:len(j)]).find(j)
                index2 = str(lines[i+1]).find(',')
                
                if index != -1:
                    
                    re_im = []
                    if index2 != -1:
                        for i_d,n_d in enumerate(lines[i+1:i+NoP+1]):
                            i_k = str(n_d).find(',')
                            re_im += \
                                 [float(n_d[0:i_k])+1j*float(n_d[i_k+1:])]
                            dataDict[j+str(l2)] =  re_im
                        l2 +=1
                    else:
                        for i_d,n_d in enumerate(lines[i+1:i+NoP+1]):
                            i_k = str(n_d).find(',')
                            re_im += \
                                 [int(n_d)]
                            dataDict[j] =  re_im


        return dataDict
